//
//  RCServiceMainVC.m
//  RocketProject
//
//  Created by chen jiedan on 13-9-26.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCServiceMainVC.h"
#import "AppDelegate.h"
#import "RCOrderManagerVC.h"
#import "RCFansListVC.h"
#import "CommonDefines.h"
#import "UIColor-Expanded.h"
#import "GloableEngineService.h"
#import "NSString+NSString_Ex_.h"
#import "RCShopManageViewController.h"

@interface RCServiceMainVC (){
    UILabel *label1;
    UILabel *label2;
}

@end

@implementation RCServiceMainVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
//    UILabel *t =[[UILabel alloc] initWithFrame:CGRectMake(0, 100, 320, 40)];
//    t.text = @"在这里加代码。。。RCServiceMainVC.m";
//    [self.viewContainer addSubview:t];
//    [t release];
    
    UIButton *rightBtn = [[[UIButton alloc] init] autorelease];
    [rightBtn addTarget:self action:@selector(serverLogout) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setImage:[UIImage imageNamed:@"icon_RCUserVC_logout"] forState:UIControlStateNormal];
    
    self.navigationItem.rightBarButtonItem = [self createRightBarButtonItemWithButton:rightBtn];
    
    
//    UIButton *tb = [[UIButton alloc] initWithFrame:CGRectMake(40, 100, 40, 30)];
//    [self.viewContainer addSubview:tb];
//    [tb addTarget:self action:@selector(tbClick) forControlEvents:UIControlEventTouchUpInside];
//    [tb setBackgroundColor:[UIColor yellowColor]];
//    [tb release];
//    
//    
//    UIButton *tp = [[UIButton alloc] initWithFrame:CGRectMake(140, 100, 40, 30)];
//    [self.viewContainer addSubview:tp];
//    [tp addTarget:self action:@selector(tpClick) forControlEvents:UIControlEventTouchUpInside];
//    [tp setBackgroundColor:[UIColor yellowColor]];
//    [tp release];
//    
//    
//    UIButton *tb1 = [[UIButton alloc] initWithFrame:CGRectMake(40, 150, 40, 30)];
//    [self.viewContainer addSubview:tb1];
//    [tb1 addTarget:self action:@selector(tb1Click) forControlEvents:UIControlEventTouchUpInside];
//    [tb1 setBackgroundColor:[UIColor blueColor]];
//    [tb1 release];
//    
//    UIButton *tb2 = [[UIButton alloc] initWithFrame:CGRectMake(40, 190, 40, 30)];
//    [self.viewContainer addSubview:tb2];
//    [tb2 addTarget:self action:@selector(tb2Click) forControlEvents:UIControlEventTouchUpInside];
//    [tb2 setBackgroundColor:[UIColor purpleColor]];
//    [tb2 release];
//
//
//    UIButton *tb3 = [[UIButton alloc] initWithFrame:CGRectMake(40, 240, 40, 30)];
//    [self.viewContainer addSubview:tb3];
//    [tb3 addTarget:self action:@selector(tb3Click) forControlEvents:UIControlEventTouchUpInside];
//    [tb3 setBackgroundColor:[UIColor purpleColor]];
//    [tb3 release];
}



- (void) viewWillAppear:(BOOL)animated
{
    [self createCityPlace];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([indexPath row] == 0 ) {
        MainPageNearbyCell *cell = [[MainPageNearbyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainPageNearbyCell" withShopMode:YES];
        cell.delegate = self;
        return cell;
    }else if ([indexPath row] == 2 ){
        MainPageNormalCell *cell = [[MainPageNormalCell alloc] initWithTitle:@"排行榜" subTitle:@"找到最棒的商家"];
        return [cell autorelease];
    }else if([indexPath row] == 3 ){
        MainPageNormalCell *cell = [[MainPageNormalCell alloc] initWithTitle:@"搜全城" subTitle:@"按商区查询，找遍城市每个角落"];
        return [cell autorelease];
    }else if([indexPath row] == 4 ){
        MainPageNormalCell *cell = [[MainPageNormalCell alloc] initWithTitle:@"美食" subTitle:@"满足你的胃，找到你想要的"];
        return [cell autorelease];
    }else if([indexPath row] == 5 ){
        MainPageNormalCell *cell = [[MainPageNormalCell alloc] initWithTitle:@"优惠" subTitle:@"超值优惠，随意挑选，尽情享受"];
        return [cell autorelease];
    }else if([indexPath row] == 1 ){
        MainPageNormalCell *cell = [[MainPageNormalCell alloc] initWithTitle:@"积分商城" subTitle:@"海量积分商品，任你兑换"];
        return [cell autorelease];
    }
    return nil;

    
}


-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}
#pragma
#pragma mark Cell Button Click
- (void) didClickType:(NSInteger)index withTitle:(NSString *)title
{
    if (index == 0) {
//        RCOrderManagerVC *vc = [[RCOrderManagerVC alloc] initWithVCType:RCListType_PhotoManage];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//        [vc release];
        [self tpClick];
    }else if (index == 1){
        RCOrderManagerVC *vc = [[RCOrderManagerVC alloc] initWithVCType:RCListType_ActivityManage withUniqueID:nil];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    }else if (index == 2){
        RCOrderManagerVC *vc = [[RCOrderManagerVC alloc] initWithVCType:RCListType_ImpressiveManage withUniqueID:nil];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    }else if (index == 3){
        RCOrderManagerVC *vc = [[RCOrderManagerVC alloc] initWithVCType:RCListType_CommentManage withUniqueID:nil];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    }else if (index == 4){
        RCOrderManagerVC *vc = [[RCOrderManagerVC alloc] initWithVCType:RCListType_Order withUniqueID:nil];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    }
    
    
}


//[self createCityPlace];
//[self createSearchView];

- (void) createCityPlace
{
    UIView *leftView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 220, 40)]autorelease];
    
    label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 210, 15)];
    label1.font = [UIFont fontWithName:kFontNameHeiti size:12];
    label1.textColor = [UIColor whiteColor];
    [label1 setBackgroundColor:[UIColor clearColor]];
    [leftView addSubview:label1];
    [label1 release];

    label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 160, 15)];
    label2.font = [UIFont fontWithName:kFontNameHeiti size:12];
    label2.textColor =  [UIColor whiteColor];
    [label2 setBackgroundColor:[UIColor clearColor]];
    [leftView addSubview:label2];
    [label2 release];

    NSString *shopName = [[GloableEngineService sharedInstance] shopName];
    NSString *city = label2.text;

    if ([NSString stringIsNullOrEmpty:city]) {
        label1.text = [NSString stringWithFormat:@"商户名：%@",shopName];
        label2.text = [NSString stringWithFormat:@"城市：%@",[[GloableEngineService sharedInstance] userCityName]];
        self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:leftView] autorelease];


    }
    
}

- (void)createSearchView
{
//    [self performSelector:@selector(tpClick) withObject:nil afterDelay:2];
}


- (void) tpClick
{
//    RCFansListVC *t = [[RCFansListVC alloc] init];
//    t.vcType = FansListVCType_photoCheck;
////    t.vcType = FansListVCType_Score;
//    t.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:t animated:YES];
//    [t release];
    
    RCShopManageViewController *vc = [[RCShopManageViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    [vc release];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) serverLogout
{
    [RCAppDelegate serverLogoutSuccess];
    
}

@end
